<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*
<span class='line'>  2</span> ********************************************************************************
<span class='line'>  3</span> jOWE - javascript Opensource Word Engine
<span class='line'>  4</span> http://code.google.com/p/jowe/
<span class='line'>  5</span> ********************************************************************************
<span class='line'>  6</span> 
<span class='line'>  7</span> Copyright (c) 2010-2012 Ludovic L.
<span class='line'>  8</span> 
<span class='line'>  9</span> Permission is hereby granted, free of charge, to any person obtaining
<span class='line'> 10</span> a copy of this software and associated documentation files (the
<span class='line'> 11</span> "Software"), to deal in the Software without restriction, including
<span class='line'> 12</span> without limitation the rights to use, copy, modify, merge, publish,
<span class='line'> 13</span> distribute, sublicense, and/or sell copies of the Software, and to
<span class='line'> 14</span> permit persons to whom the Software is furnished to do so, subject to
<span class='line'> 15</span> the following conditions:
<span class='line'> 16</span> The above copyright notice and this permission notice shall be
<span class='line'> 17</span> included in all copies or substantial portions of the Software.
<span class='line'> 18</span> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
<span class='line'> 19</span> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
<span class='line'> 20</span> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
<span class='line'> 21</span> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
<span class='line'> 22</span> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
<span class='line'> 23</span> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
<span class='line'> 24</span> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<span class='line'> 25</span> 
<span class='line'> 26</span> ********************************************************************************
<span class='line'> 27</span> Credit for "pnpoly" must go to W. Randolph Franklin available at :
<span class='line'> 28</span> http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
<span class='line'> 29</span> 
<span class='line'> 30</span> ********************************************************************************
<span class='line'> 31</span> 
<span class='line'> 32</span>  */</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 34</span> </span><span class="COMM">/**
<span class='line'> 35</span>  * @fileOverview This file contains the jowe_ui_2d_hexa object (&lt;a href="http://code.google.com/p/jowe/">jOWE&lt;/a>).
<span class='line'> 36</span>  * @author Ludovic Lefebvre
<span class='line'> 37</span>  * @version 1.0
<span class='line'> 38</span>  */</span><span class="WHIT">
<span class='line'> 39</span> 
<span class='line'> 40</span> </span><span class="COMM">/**
<span class='line'> 41</span>  * Draws an hexagonal map from a given heightmap object in a canvas tag.
<span class='line'> 42</span>  * @class Draws an map with hexagonal tiles.
<span class='line'> 43</span>  * @see How to use the &lt;a href="http://jowe.ouebfrance.com/examples-jowe-ui-2d-hexa.html">jowe_ui_2d_hexa&lt;/a> object?
<span class='line'> 44</span>  * @param {string} canvas_id          Id of the canvas tag to be used to draw the hexagonal map.
<span class='line'> 45</span>  * @param {number} canvas_width       Width of the canvas.
<span class='line'> 46</span>  * @param {number} canvas_height      Height of the canvas.
<span class='line'> 47</span>  * @param {string} [canvas_backcolor="#000"] Background color to be used when drawing the canvas.
<span class='line'> 48</span>  */</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 49</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">jowe_ui_2d_hexa</span><span class="PUNC">(</span><span class="NAME">canvas_id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">canvas_width</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">canvas_height</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">canvas_backcolor</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">    </span><span class="STRN">"use strict"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">        </span><span class="NAME">height</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">        </span><span class="NAME">backcolor</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'#000'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">        </span><span class="NAME">canvas_map</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> 
<span class='line'> 57</span> </span><span class="WHIT">    </span><span class="COMM">// Handler to the canvas object used to display the map.</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">    </span><span class="NAME">this.map</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">    </span><span class="COMM">//</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">    </span><span class="NAME">this.cursor</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">                    </span><span class="NAME">visible</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">                    </span><span class="NAME">x</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">                    </span><span class="NAME">y</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">                    </span><span class="NAME">mX</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">                    </span><span class="NAME">mY</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">                    </span><span class="NAME">color</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"#ff0000"</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">                  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">canvas_width</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">canvas_width</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">isNaN</span><span class="PUNC">(</span><span class="NAME">canvas_width</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">        </span><span class="NAME">width</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">canvas_width</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">canvas_height</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">canvas_height</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">isNaN</span><span class="PUNC">(</span><span class="NAME">canvas_height</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">        </span><span class="NAME">height</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">canvas_height</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">canvas_backcolor</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">canvas_backcolor</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">        </span><span class="NAME">backcolor</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">canvas_backcolor</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 83</span> 
<span class='line'> 84</span> </span><span class="WHIT">    </span><span class="NAME">canvas_map</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">document.getElementById</span><span class="PUNC">(</span><span class="NAME">canvas_id</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> 
<span class='line'> 86</span> </span><span class="WHIT">    </span><span class="COMM">// Test for canvas availability.</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">canvas_map.getContext</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">        </span><span class="NAME">canvas_map.width</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">        </span><span class="NAME">canvas_map.height</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">height</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">        </span><span class="NAME">this.map</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">canvas_map.getContext</span><span class="PUNC">(</span><span class="STRN">'2d'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">        </span><span class="NAME">this.map.fillStyle</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">backcolor</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">        </span><span class="NAME">this.map.fillRect</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">height</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 94</span> 
<span class='line'> 95</span> </span><span class="WHIT">    </span><span class="COMM">/**
<span class='line'> 96</span>      * This function draws an hexagonal map in the canvas.
<span class='line'> 97</span>      * @param {array} items Array of vertices in the polygon.
<span class='line'> 98</span>      * @param {number} angle Number containing the x-coordinates of the polygon's vertices.
<span class='line'> 99</span>      * @param {number} x_off X-coordinate of the offset point.
<span class='line'>100</span>      * @param {number} x_off Y-coordinate of the offset point.
<span class='line'>101</span>      * @param {number} height Height of the hexagonal tiles.
<span class='line'>102</span>      * @param {number} width Width of the hexagonal tiles.
<span class='line'>103</span>      * @param {array} colors Array of color used to draw the map.
<span class='line'>104</span>      * @param {boolean} [alt=false] To be set to True for straight map (default is False - skew map).
<span class='line'>105</span>      * @param {number} [border=0.4] Defines the space between tiles.
<span class='line'>106</span>      * @protected
<span class='line'>107</span>      */</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">    </span><span class="NAME">this.draw</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">items</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">angle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">x_off</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y_off</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">h</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">w</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">colors</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">alt</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">border</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>109</span> 
<span class='line'>110</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="COMM">// used for "for" loops.</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT">            </span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">            </span><span class="COMM">// temporarly x,y coordinates.</span><span class="WHIT">
<span class='line'>113</span> </span><span class="WHIT">            </span><span class="NAME">tx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT">            </span><span class="NAME">mtx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">mty</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">            </span><span class="NAME">wdiv2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">w</span><span class="PUNC">/</span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">            </span><span class="NAME">hdiv2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">h</span><span class="PUNC">/</span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">            </span><span class="NAME">hdiv4</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">h</span><span class="PUNC">/</span><span class="NUMB">4</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">            </span><span class="COMM">// distance between tiles.</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">            </span><span class="NAME">dist</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0.5</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT">            </span><span class="COMM">// dimension of the heightmap.</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">            </span><span class="NAME">xc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">items.length</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>122</span> </span><span class="WHIT">            </span><span class="NAME">yc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">items</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">length</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">            </span><span class="COMM">// corners of the drawing zone :</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">            </span><span class="COMM">// pt#[0] = top left</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT">            </span><span class="COMM">// pt#[1] = top right</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT">            </span><span class="COMM">// pt#[2] = bottom right</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">            </span><span class="COMM">// pt#[3] = bottom left</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">            </span><span class="NAME">ptx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">pty</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> 
<span class='line'>130</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">alt</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">alt</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">alt</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT">          </span><span class="NAME">alt</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">border</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">border</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">isNaN</span><span class="PUNC">(</span><span class="NAME">border</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT">            </span><span class="NAME">dist</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">border</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT">            </span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT">        </span><span class="COMM">// Initialize the canvas.</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT">        </span><span class="NAME">this.map.fillStyle</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">backcolor</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">        </span><span class="NAME">this.map.fillRect</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">height</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">        </span><span class="NAME">this.map.width</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT">        </span><span class="COMM">// Save the current context before transformations.</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT">        </span><span class="NAME">this.map.save</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> 
<span class='line'>145</span> </span><span class="WHIT">        </span><span class="COMM">// [step 1]</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT">        </span><span class="COMM">// Going to the relative position that define the center of the map.</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">        </span><span class="NAME">this.map.translate</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">width</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">x_off</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">height</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">y_off</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">        </span><span class="COMM">// [step 2]</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT">        </span><span class="COMM">// Rotation according to the user choice.</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT">        </span><span class="COMM">// Beware, that's define the pivot point to the center of the map,</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT">        </span><span class="COMM">// not to the current center of the canvas.</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT">        </span><span class="COMM">// If we want to rotate from the center of the canvas, the offset</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT">        </span><span class="COMM">// coordinate needs to be processed accordingly.</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT">        </span><span class="NAME">this.map.rotate</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NAME">angle</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">/</span><span class="NUMB">180</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT">        </span><span class="COMM">// [step 3]</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT">        </span><span class="COMM">// At last we go in the center of the current map.</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">alt</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT">          </span><span class="NAME">mtx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">xc</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT">    </span><span class="NAME">wdiv2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT">  </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">yc</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT">          </span><span class="NAME">mtx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT">  </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">xc</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>161</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT">        </span><span class="NAME">mty</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">yc</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">        </span><span class="NAME">this.map.translate</span><span class="PUNC">(</span><span class="NAME">mtx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">mty</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">        </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">        </span><span class="COMM">// TODO : build a smaller rectangle than the canvas and check that at least one of its corner is included</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT">        </span><span class="COMM">//        in the rectangle of the map, if not return false.</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT">        </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">        </span><span class="COMM">// Coordinates of the corners of the drawing area.</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">        </span><span class="COMM">// Each tile that's not inside this area won't be drawn.</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">        </span><span class="NAME">ptx</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">ptx</span><span class="PUNC">[</span><span class="NUMB">3</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="PUNC">(</span><span class="NAME">width</span><span class="WHIT">  </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">x_off</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT">        </span><span class="NAME">pty</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pty</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="PUNC">(</span><span class="NAME">height</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">y_off</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">h</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT">        </span><span class="NAME">ptx</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">ptx</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">  </span><span class="PUNC">(</span><span class="NAME">width</span><span class="WHIT">  </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">x_off</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT">        </span><span class="NAME">pty</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pty</span><span class="PUNC">[</span><span class="NUMB">3</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">  </span><span class="PUNC">(</span><span class="NAME">height</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">y_off</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">h</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>176</span> </span><span class="WHIT">        </span><span class="COMM">// Loop to take in account the rotation and the last offset.</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT">        </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">            </span><span class="COMM">// Rotate the point coordinate.</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT">            </span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.floor</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">angle</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">/</span><span class="NUMB">180</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">ptx</span><span class="PUNC">[</span><span class="NAME">n</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">angle</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">/</span><span class="NUMB">180</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">pty</span><span class="PUNC">[</span><span class="NAME">n</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT">            </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.floor</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">angle</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">/</span><span class="NUMB">180</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">ptx</span><span class="PUNC">[</span><span class="NAME">n</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">angle</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">/</span><span class="NUMB">180</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">pty</span><span class="PUNC">[</span><span class="NAME">n</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>181</span> </span><span class="WHIT">            </span><span class="COMM">// Then add the dimension of the heightmap according to the last translation (step 3)</span><span class="WHIT">
<span class='line'>182</span> </span><span class="WHIT">            </span><span class="NAME">ptx</span><span class="PUNC">[</span><span class="NAME">n</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">mtx</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>183</span> </span><span class="WHIT">            </span><span class="NAME">pty</span><span class="PUNC">[</span><span class="NAME">n</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">mty</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>184</span> </span><span class="WHIT">            </span><span class="WHIT">
<span class='line'>185</span> </span><span class="WHIT">            </span><span class="COMM">/* [uncomment for dev only :]
<span class='line'>186</span>             this.map.fillStyle = '#00ffff';
<span class='line'>187</span>             this.map.fillRect(ptx[n] - 2, pty[n] - 2, 4, 4);
<span class='line'>188</span>             */</span><span class="WHIT">
<span class='line'>189</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">        </span><span class="COMM">/* [uncomment for dev only :]
<span class='line'>192</span>         this.map.beginPath();
<span class='line'>193</span>         this.map.width = 1;
<span class='line'>194</span>         this.map.strokeStyle = '#00ffff';
<span class='line'>195</span>         this.map.moveTo(ptx[0],pty[0]);
<span class='line'>196</span>         this.map.lineTo(ptx[1],pty[1]);
<span class='line'>197</span>         this.map.lineTo(ptx[2],pty[2]);
<span class='line'>198</span>         this.map.lineTo(ptx[3],pty[3]);
<span class='line'>199</span>         this.map.lineTo(ptx[0],pty[0]);
<span class='line'>200</span>         this.map.stroke();
<span class='line'>201</span>         */</span><span class="WHIT">
<span class='line'>202</span> 
<span class='line'>203</span> </span><span class="WHIT">        </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT">        </span><span class="COMM">// TODO : simplify (factorize) calculations to speed up the loop.</span><span class="WHIT">
<span class='line'>205</span> </span><span class="WHIT">        </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>206</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>207</span> </span><span class="WHIT">        </span><span class="COMM">// Going through each tile.</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT">        </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">yc</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT">            </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">3</span><span class="PUNC">/</span><span class="NUMB">4</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">h</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT">            </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">xc</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">                </span><span class="COMM">// Calculates the "top-left" coordinate of the current tile.</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT">                </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">alt</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>213</span> </span><span class="WHIT">                  </span><span class="COMM">// Skew map.</span><span class="WHIT">
<span class='line'>214</span> </span><span class="WHIT">                  </span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>215</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>216</span> </span><span class="WHIT">                  </span><span class="COMM">// Straight map.</span><span class="WHIT">
<span class='line'>217</span> </span><span class="WHIT">                  </span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">w</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dist</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>218</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>219</span> </span><span class="WHIT">                </span><span class="COMM">// Draws the tile only if it's inside the drawing area.</span><span class="WHIT">
<span class='line'>220</span> </span><span class="WHIT">                </span><span class="COMM">// (original method from http://stackoverflow.com/questions/3990343/3d-drawing-in-canvas-with-htmljs)</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT">                </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">pnpoly</span><span class="PUNC">(</span><span class="NUMB">4</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ptx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">pty</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>222</span> </span><span class="WHIT">                </span><span class="WHIT">
<span class='line'>223</span> </span><span class="WHIT">                    </span><span class="NAME">fillHexaTile</span><span class="PUNC">(</span><span class="NAME">this.map</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">colors</span><span class="PUNC">[</span><span class="NAME">items</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">y</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>224</span> </span><span class="WHIT">                    </span><span class="WHIT">
<span class='line'>225</span> </span><span class="WHIT">                    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.map.isPointInPath</span><span class="PUNC">(</span><span class="NAME">this.cursor.mX</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.cursor.mY</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>226</span> </span><span class="WHIT">                      </span><span class="NAME">this.cursor.x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>227</span> </span><span class="WHIT">                      </span><span class="NAME">this.cursor.y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT">                      </span><span class="NAME">this.cursor.mX</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tx</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">                      </span><span class="NAME">this.cursor.mY</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>230</span> </span><span class="WHIT">                    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>233</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>234</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>235</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.cursor.visible</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>236</span> </span><span class="WHIT">          </span><span class="NAME">this.map.lineWidth</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">          </span><span class="NAME">strokeHexaTile</span><span class="PUNC">(</span><span class="NAME">this.map</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.cursor.color</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.cursor.mX</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.cursor.mY</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>238</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">        </span><span class="COMM">// Restores the context.</span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">        </span><span class="NAME">this.map.restore</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">    </span><span class="COMM">/**
<span class='line'>245</span>      * This function draws a filled hexagon.
<span class='line'>246</span>      * @param {*} m Canvas context to draw on.
<span class='line'>247</span>      * @param {string} c Array containing the x-coordinates of the polygon's vertices.
<span class='line'>248</span>      * @param {number} tx X-coordinate of the center of the hexagon.
<span class='line'>249</span>      * @param {number} tx X-coordinate of the center of the hexagon.
<span class='line'>250</span>      * @param {number} wdiv2 Width divided by 2.
<span class='line'>251</span>      * @param {number} hdiv2 Height divided by 2.
<span class='line'>252</span>      * @param {number} hdiv4 Height divided by 4.
<span class='line'>253</span>      * @private
<span class='line'>254</span>      */</span><span class="WHIT">
<span class='line'>255</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">fillHexaTile</span><span class="PUNC">(</span><span class="NAME">m</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">c</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>256</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>257</span> </span><span class="WHIT">        </span><span class="NAME">m.beginPath</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>258</span> </span><span class="WHIT">        </span><span class="NAME">m.fillStyle</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">c</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">        </span><span class="NAME">m.moveTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>261</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>262</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>263</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>264</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>265</span> </span><span class="WHIT">        </span><span class="NAME">m.fill</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>266</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>267</span> 
<span class='line'>268</span> </span><span class="WHIT">    </span><span class="COMM">/**
<span class='line'>269</span>      * This function draws an empty hexagon.
<span class='line'>270</span>      * @param {*} m Canvas context to draw on.
<span class='line'>271</span>      * @param {string} c Array containing the x-coordinates of the polygon's vertices.
<span class='line'>272</span>      * @param {number} tx X-coordinate of the center of the hexagon.
<span class='line'>273</span>      * @param {number} tx X-coordinate of the center of the hexagon.
<span class='line'>274</span>      * @param {number} wdiv2 Width divided by 2.
<span class='line'>275</span>      * @param {number} hdiv2 Height divided by 2.
<span class='line'>276</span>      * @param {number} hdiv4 Height divided by 4.
<span class='line'>277</span>      * @private
<span class='line'>278</span>      */</span><span class="WHIT">
<span class='line'>279</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">strokeHexaTile</span><span class="PUNC">(</span><span class="NAME">m</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">c</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>280</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>281</span> </span><span class="WHIT">        </span><span class="NAME">m.beginPath</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>282</span> </span><span class="WHIT">        </span><span class="NAME">m.strokeStyle</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">c</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>283</span> </span><span class="WHIT">        </span><span class="NAME">m.moveTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>284</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>285</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>286</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hdiv2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>287</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>288</span> </span><span class="WHIT">        </span><span class="NAME">m.lineTo</span><span class="PUNC">(</span><span class="NAME">tx</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">wdiv2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ty</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">hdiv4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>289</span> </span><span class="WHIT">        </span><span class="NAME">m.closePath</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>290</span> </span><span class="WHIT">        </span><span class="NAME">m.stroke</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>291</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>292</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>293</span> </span><span class="WHIT">    </span><span class="COMM">/**
<span class='line'>294</span>      * This function find if a point lies within a polygon.
<span class='line'>295</span>      * @param {number} nvert Number of vertices in the polygon.
<span class='line'>296</span>      * @param {array} vertx Array containing the x-coordinates of the polygon's vertices.
<span class='line'>297</span>      * @param {array} verty Array containing the y-coordinates of the polygon's vertices.
<span class='line'>298</span>      * @param {number} testx X-coordinate of the test point.
<span class='line'>299</span>      * @param {number} testy Y-coordinate of the test point.
<span class='line'>300</span>      * @return {boolean}
<span class='line'>301</span>      * @private
<span class='line'>302</span>      */</span><span class="WHIT">
<span class='line'>303</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">pnpoly</span><span class="PUNC">(</span><span class="NAME">nvert</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">vertx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">verty</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">testx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">testy</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">     </span><span class="WHIT">
<span class='line'>304</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">c</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>305</span> </span><span class="WHIT">        </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">nvert</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">nvert</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>306</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">verty</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">testy</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">verty</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">testy</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>307</span> </span><span class="WHIT">                </span><span class="PUNC">(</span><span class="NAME">testx</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">vertx</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">vertx</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">testy</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">verty</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">verty</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">verty</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">vertx</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>308</span> </span><span class="WHIT">                </span><span class="NAME">c</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">c</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>309</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>310</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">c</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>313</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>314</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.map</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>315</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>316</span> </span></pre></body></html>